<template>
	<view class="content">
		<view class="custom-navbar">
			<view class="back-button" @click="goBack">
				<uni-icons type="left" size="24"></uni-icons> <!-- 使用 uni-app 内置图标 -->
			</view>
			<view class="navbar-title">{{navigation}}</view>
		</view>
		<view class="goodsContentBox">
			<view class="goods-list">
				<view class="goodsItem" v-for="(item, index) in goodsList" :key="index" @click="goGoodsDetail(item)">
					<image :src="item.pictureIntegrationDtoS[0].pictureUrl" class="goodsImage" mode="aspectFill">
					</image>
					<view class="goodsInfo">
						<p class="goodsTitle">{{ item.commodityName }}</p>
						<view class="priceAndButton">
							<p class="goodsPrice">
								￥{{ item.commoditySpecificationBasicInformationDto.commoditySpecificationAttributeInfoDto.sellingPrice }}
							</p>
							<image class="grabButton"
								src="https://smart-biotech.oss-cn-shanghai.aliyuncs.com/wisdomClubApp/qiang.png"
								mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="!goodsList.length">
			<image style="margin:10%;" src='../../../static/null/null.png'></image>
		</view>
	</view>
</template>

<script>
	import {
		getGoods
	} from '@/api/goods.js';

	export default {
		data() {
			return {
				goodsList: [],
				navigation: ''
			}
		},
		onLoad(options) {
			console.log(options.id)
			if (options.id == "31") {
				this.navigation = '报单专区'
			} else if (options.id == "32") {
				this.navigation = '复购专区'
			} else if (options.id == "34") {
				this.navigation = '福利专区'
			}
			this.getGoodsList(options.id)
		},
		methods: {
			getGoodsList(id) {
				const params = {
					classifyId: id,
					pageSize: 20,
					pageNumber: 1,
				};
				getGoods(params).then(res => {
					this.goodsList = res.data.records
				})
			},
			goGoodsDetail(item) {
				uni.navigateTo({
					url: '/pages/classification/goodsDetail/index?id=' + item.id
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 1 // 返回上一级页面
				});
			}
		}
	}
</script>

<style lang="scss">
	@import '@/uni.scss'; // 导入全局 SCSS 变量文件

	.content {
		min-height: 100vh;
		background: linear-gradient(to bottom, #EEDED4, #FAF7F0, #FFFFFF);
	}

	.custom-navbar {
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background-color: $uni-bg-color-white;

		.back-button {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60rpx;
			height: 60rpx;
			border-radius: 50%;
			margin-top: 20rpx;
		}

		.navbar-title {
			flex-grow: 1;
			text-align: left;
			margin-top: 20rpx;
			padding-left: 34%;
		}

	}

	.goodsContentBox {
		padding: 30rpx 20rpx;
		border-radius: 30rpx;

		.titleBox {
			display: flex;
			justify-content: space-between;
			margin-bottom: 20rpx;

			.leftBoxTitle {
				font-weight: bold;
				font-size: 36rpx;
				color: #333333;
			}

			.rightBoxTitle {
				font-weight: 400;
				font-size: 26rpx;
				color: #915F3E;
			}
		}

		.goods-list {
			display: flex;
			flex-wrap: wrap;
			gap: 20rpx;

			.goodsItem {
				width: calc(50% - 12rpx); // 两个商品之间有20rpx的间隔
				background: #FFFFFF;
				border-radius: 20rpx;
				overflow: hidden;
				box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1);

				.goodsImage {
					width: 348rpx;
					height: 348rpx;
				}

				.goodsInfo {
					padding: 10rpx;

					.goodsTitle {
						font-size: 28rpx;
						font-weight: bold;
						color: #333;
						line-height: 1.2em;
						height: 2.4em;
						/* 固定高度，2行文字 */
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}

					.priceAndButton {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-top: 10rpx;

						.goodsPrice {
							font-size: 32rpx;
							color: #FF743E;
							font-weight: bold;
						}

						.grabButton {
							width: 78rpx;
							height: 66rpx;
						}
					}
				}
			}
		}
	}
</style>